package com.ruoyi.monitor;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.monitor.Vo.CityVo;
import com.ruoyi.monitor.Vo.PollutantVo;
import com.ruoyi.monitor.utils.Common.Constant;
import com.ruoyi.monitor.utils.Common.HttpUtils;
import org.apache.http.HttpResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class apiTest {
    public static void main(String[] args) throws IOException {
        SysUser user = new SysUser();
        SysUser user1 = new SysUser();
        user.setEmail("2423631557@qq.com");
        user1.setEmail("xuzexuan2000327001@163.com");
        SysUser[] users = {user,user1};
        String mails = "";
        for (int i = 0; i < users.length; i++) {
            mails+=(users[i].getEmail());
            if (i<users.length-1){
                mails+=(";");
            }
        }
        System.out.println(mails);
        String[] strings = mails.split(";");
        System.out.println(strings);
//        String host = Constant.HOST;
//        String path = Constant.RANKPATH;
//        String method = Constant.GET;
//        String appcode = Constant.APPCODE;
//        InputStream content = null;
//        Map<String, String> headers = new HashMap<String, String>();
//        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
//        headers.put("Authorization", "APPCODE " + appcode);
//        Map<String, String> querys = new HashMap<String, String>();
//        try {
//            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
//            System.out.println(response.toString());
//            content = response.getEntity().getContent();
//            //获取response的body
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        StringBuilder data = new StringBuilder();
//        try(BufferedReader reader = new BufferedReader(new InputStreamReader(content))) {
//            String c ;
//            while ((c=reader.readLine())!=null){
//                data.append(c);
//                data.append(System.getProperty("line.separator"));
//            }
//
//        }
//
//        transferJSON(data.toString());


    }

    public static Object transferJSON(String content){
        ObjectMapper mapper = new ObjectMapper();
        PollutantVo pollutantVo = new PollutantVo();
        List<CityVo> cityVos = new ArrayList<>();
        try {
            JsonNode jsonNode = mapper.readTree(content);
            JsonNode path = jsonNode.path("showapi_res_body");
            System.out.println(path);
            JsonNode pm = path.path("list");
            System.out.println(pm.toString());
            System.out.println("\"name\"");
            String all = pm.toString().replaceAll("\"_\"", "\"0\"");
            List<CityVo> cityVoList = JSONObject.parseObject(all,new TypeReference<List<CityVo>>(){});
            System.out.println(cityVoList);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return pollutantVo;
    }

    //方法三：
    public static boolean isNumeric(String str){
        for (int i = str.length();--i>=0;){
            if (!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }
    public static String JsonNodeToValue(JsonNode node){
        String data = node.toString().replace("\"", "");
        System.out.println(data);
        if (isNumeric(data)){
            return data;
        }else if (data.contains("_")||"".equals(data)){
            System.out.println(1);
            return "0";
        }else {
            return data;
        }
    }
}
